package com.netMgr.webServer{
	import com.pqmvc.PQMVC;
	public class HttpMgr{
		/**是否队列加载**/
		static public var queue:Boolean=false;
		/**待加载列表，队列加载使用**/
		static private var requestList:Array=[];
		/**当前是否有请求，队列加载使用**/
		static private var requestting:Boolean=false;
		/**当前正在请求的数据**/
		static private var currentRequest:HttpRequestVo;
		/**加载器**/
		static private var requester:HttpRequest=new HttpRequest();
		/**头部信息**/
		static public var header:Object={};
		public function HttpMgr()
		{
		}
		/**请求数据**/
		static public function request(v:HttpRequestVo):void{
			v.header=header;
			v.header=v.param;
			if(!queue)HttpRequest.request(v);
			else{
				requestList.push(v);
				if(requestting)return;
				requestNext();
			}
		}
		/**执行下一个请求**/
		static private function requestNext():void{
			requestting=true;
			currentRequest=requestList.shift();
			var v:HttpRequestVo=new HttpRequestVo();
			v.url=currentRequest.url;
			v.param=currentRequest.param;
			v.type=currentRequest.type;
			v.format=currentRequest.format;
			v.header=currentRequest.header;
			v.onComplete=onComplete;
			requester.load(v);
		}
		static private function onComplete(v:Object):void{
			requestting=false;
			if(currentRequest.onComplete)currentRequest.onComplete(v);
			if(currentRequest.event)PQMVC.self.call(currentRequest.event,v);
			currentRequest=null;
			if(requestList.length>0)requestNext();
		}
	}
}